<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="活动筛选" prop="activityName">
        <el-select v-model="queryParams.activityName" placeholder="请选择活动名称">
          <el-option
            v-for="item in activityList"
            :key="item.id"
            :value="parseInt(item.id)"
            :label="item.activityName"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="20">
      <el-col :span="24" :xs="24">
        <!-- <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="warning"
              icon="el-icon-download"
              size="mini"
              @click="handleExport"
              v-hasPermi="['rank:integral:export']"
            >导出</el-button>
          </el-col>
        </el-row>-->

        <el-table v-loading="loading" :data="rankList" @selection-change="handleSelectionChange">
          <el-table-column label="姓名" align="center" prop="nickname"/>
          <el-table-column label="最高分" align="center" prop="maxScore"/>
          <el-table-column label="参与次数" align="center" prop="numAttempts"/>
          <el-table-column label="排名" align="center" prop="rank"/>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { getExamRecordRankAll } from "@/api/exam/integralRecord";
import { getActivityPage } from "@/api/exam/activity";
export default {
  name: "Rank",
  components: {},
  dicts: [],
  data() {
    return {
      // 机构名称
      deptName: undefined,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      genderStatusOptions: [],
      // 排行列表
      rankList: [],
      //活动列表
      activityList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 0,
        pageSize: 15,
        activityId: null,
        type: 0
      },
      queryParams2: {
        pageNum: 0,
        pageSize: 100
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询排行列表 */
    getList() {
      this.loading = true;

      getActivityPage(this.queryParams2).then(response => {
        this.activityList = response.data.list;
        this.queryParams.activityId = this.activityList[0].id;
        getExamRecordRankAll(this.queryParams).then(response => {
          this.rankList = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        });
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    //排序
    // tableSortChange(column) {
    // console.log(column)
    // return
    //   this.listQuery.pageNo = 1
    //   if (column.order === 'descending') {
    //     this.listQuery.sortby = column.prop
    //     this.listQuery.order = 'desc'
    //   } else {
    //     this.listQuery.sortby = column.prop
    //     this.listQuery.order = 'asc'
    //   }
    // },

    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "rank/integral/export",
        {
          ...this.queryParams
        },
        `rank_${new Date().getTime()}.xlsx`
      );
    },
    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download(
        "member/UmsMember/importTemplate",
        {},
        `member_template_${new Date().getTime()}.xlsx`
      );
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(
        "<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" +
          response.msg +
          "</div>",
        "导入结果",
        { dangerouslyUseHTMLString: true }
      );
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
